 //$route.params.menuindex 
<template>
<gj-loadmore :bottom-method="loadBottom" :bottomPullText="bottomPullText" ref="loadmore">
    <div class="rockstock-list portfolio-list">
    <div class="hbox">
        <div class="hbox-row" v-for="item in dataList" @click="clickRow(item)">
            <div class="col-1 hbox-row-item">
                <span>{{ProfitLabel}}</span>
                <div class="profit color-green" :class="{'color-green':isNegativeProfit(item),'color-red':!isNegativeProfit(item)}">{{getProfit(item)}}%</div>
            </div>
            <div class="col-2 hbox-row-item">
                <div class="group_name">{{item.group_name}}</div>
                <div class="nick_name"><span>{{item.nickname}}</span><span>创建</span></div>
                <div class="block_text">
                    <div class="block_none" v-if="item.block_text.length==0"></div>
                    <template v-else v-for="(tag,index) in item.block_text[0]">
                        <div class="group-tag" v-if="tag!=''">{{tag}}</div>
                        <div v-else-if="index==3" class="block_none"></div>
                    </template>
                </div>
            </div>
            <div class="col-3 hbox-row-item">
                <span v-if="item.stealers==''||item.stealers==0">还没有人偷师</span>
                <template v-else>
                    <div class="learn_num">{{item.stealers}}</div>
                    <span>人偷师</span>
                </template>
            </div>
            <div class="col-4 hbox-row-item">
                <i class="iconfont icon-xiangyou"></i>
            </div>
            <img class="zhuhe" src="~assets/images/portfolio/zuhe.png">
        </div>
    </div>
  </div>
  </div>
</gj-loadmore>
</template>

<script>
import RemoteDAO from 'common/remoteDAO'
import LocalDAO from 'common/localDAO'
import CommonUtil from 'common/common.util'
import LoadMore from 'components/LoadMore'

export default {
    components:{
        "gj-loadmore":LoadMore
    },
	data(){
		return {
			dataList:[],
            pageInfo:{
                pageNum:0,
                pageSize:10
            },
            sortType:[2,3,4,1],
            bottomPullText:"上拉加载更多牛组合"
		}
	},
    watch: {
        '$route':{
            handler: function (to, from) {
              this.dataList = [];
              this.pageInfo.pageNum = 0;
              this.$refs.loadmore.reset();
            },
            deep: true
        }
    },
    computed:{
        ProfitLabel(){
            var vm = this;

            switch(Number(vm.$route.params.menuindex)){
                case 0:
                case 3:
                    return "日收益率";
                case 1:
                    return "月收益率";
                case 2:
                    return "总收益率";
            }
        }
    },
	methods:{
        getPageParam(){
            return {
                start:this.pageInfo.pageNum*this.pageInfo.pageSize,
                end:(this.pageInfo.pageNum+1)*this.pageInfo.pageSize
            }
        },
        loadBottom() {
            let vm = this;

            vm.fetchData(function (allLoaded,error) {
              if(error){
                vm.$refs.loadmore.onBottomError(error);//单次加载失败或者没有数据，error为报错信息，如果是没有数据，写暂无数据
              }else if (allLoaded) {
                vm.$refs.loadmore.onBottomAllLoaded();//全部数据加载完成
              } else {
                vm.$refs.loadmore.onBottomLoaded(); //单次加载成功
              }
            });
        },
        isNegativeProfit(item){
            var vm = this;

            switch(Number(vm.$route.params.menuindex)){
                case 0:
                case 3:
                    return item.day_profit<0;
                case 1:
                    return item.month_profit<0;
                case 2:
                    return item.total_profit<0;
            }
        },
        getProfit(item){
            var vm = this;

            switch(Number(vm.$route.params.menuindex)){
                case 0:
                case 3:
                    return CommonUtil.toFixed(item.day_profit,2);
                case 1:
                    return CommonUtil.toFixed(item.month_profit,2);
                case 2:
                    return CommonUtil.toFixed(item.total_profit,2);
            }
        },
        clickRow(item){
            //跳转组合详情页面
            var vm = this;
            vm.$router.push({ path: '/groupdetail', query: { clientId:item.client_id,groupId:item.group_id}})
        },
        fetchData(afterFetchData){
            var vm = this,
                error,
                allLoaded = false,
                pageParam = vm.getPageParam();

            RemoteDAO.callJCL30008(pageParam.end, pageParam.start, vm.sortType[vm.$route.params.menuindex], function (response) {
                if(Number(response.error) == 0){
                    vm.dataList = vm.dataList.concat(response.data.body.data);

                    if(vm.dataList.length == 0){
                      error = '暂无数据'
                    }else if (response.data.body.data.length < vm.pageInfo.pageSize){
                      allLoaded = true
                    }
                        
                    if(!allLoaded){
                        vm.pageInfo.pageNum++;
                    }

                    switch (vm.sortType[vm.$route.params.menuindex]) {
                        case 2:
                            LocalDAO.setRockPortfolioDay({"groupList": vm.dataList});
                            break;
                        case 3:
                            LocalDAO.setRockPortfolioMonth({"groupList": vm.dataList});
                            break;
                        case 4:
                            LocalDAO.setRockPortfolioTotal({"groupList": vm.dataList});
                            break;
                        case 1:
                            LocalDAO.setRockPortfolioPopular({"groupList": vm.dataList});
                            break;
                        default:
                            break;
                    }
                }else{
                    error = response.data;
                    vm.$refs.loadmore.onBottomError();
                }
                
                afterFetchData(allLoaded, error);
            });
        }
	},
	created(){
        var vm = this;

        // vm.fetchData();
	}
}
</script>

<style lang="css" scoped>
.col-2.hbox-row-item .group-tag{
    margin-right: 3px;
}
.portfolio-list .col-1{
    width: 30%;
}
.portfolio-list .col-2{
    width: 40%;
}
.portfolio-list .col-3{
    width: 26%;
}
.portfolio-list .col-4{
    width: 8%;
}
</style>
